import ch.bfh.medinfo.javafx.dice.definition.Dice;
import ch.bfh.medinfo.javafx.dice.implementation.FairDice;
import ch.bfh.medinfo.javafx.dice.implementation.UnFairDice;

public class TestFairDice {

	public TestFairDice() {
		if (testFairDice())
			System.out.println("Success");
		else
			System.out.println("Fail");
	}

	public boolean testFairDice() {
		DiceTester diceTester = new DiceTester();

		Dice dice = null;
		// Not allowed by compiler:
		// dice=new FairDice();
		// dice=new FairDice(1);

		{ // Test minValue == maxValue
			try {
				dice = new FairDice(1, 1);
				try {
					diceTester.testDice(dice);
				} catch (IllegalArgumentException ex) {
					ex.printStackTrace();
					return false;
				}
			} catch (IllegalArgumentException ex) {
				// OK, the FairDice does not allow this
			}

		}
		{ // Test minValue > maxValue
			try {
				dice = new FairDice(2, 1);
				// BAD, The use-case requires the minimal value to be at the
				// first position (By contract)
				return false;
			} catch (IllegalArgumentException ex) {
				// OK, FairDice does not allow this
			}

		}
		{ // Test minValue > maxValue
			try {
				dice = new FairDice(1, 2);
				// OK, then test the ADT-requirements
				try {
					diceTester.testDice(dice);
				} catch (IllegalArgumentException ex) {
					ex.printStackTrace();
					return false;
				}
			} catch (Exception ex) {
				// BAD, FairDice must allow that
				return false;
			}

		}
		{ // Test 'normal' dice
			try {
				dice = new FairDice(1, 6);
				// OK, then test the ADT-requirements
				try {
					diceTester.testDice(dice);
				} catch (IllegalArgumentException ex) {
					ex.printStackTrace();
					return false;
				}
			} catch (Exception ex) {
				// BAD, FairDice must allow that
				return false;
			}

		}
		{ // Test specialDice
			try {
				dice = new FairDice(-6, 6);
				// OK, then test the ADT-requirements
				try {
					diceTester.testDice(dice);
				} catch (IllegalArgumentException ex) {
					ex.printStackTrace();
					return false;
				}
			} catch (Exception ex) {
				// BAD, FairDice must allow that
				return false;
			}

		}
		// every test passed perfectly -> use-cases are covered 100%
		return true;
	}

	public static void main(String[] args) {
		new TestFairDice();
	}

}
